from django.shortcuts import render
from django.http import JsonResponse
# from django.shortcuts import render, render_to_response
from django.shortcuts import HttpResponseRedirect, HttpResponse
from django.http import JsonResponse
import json
import random
from django.conf import settings
from django.views.decorators.csrf import csrf_exempt
import json
from .models import UserInfo

def hello(request):
    json_data = {
        'code': 2000,
        'msg': '连接成功',
        'data':[1,2,3,4,6,5,9,7,8]
    }
    return JsonResponse(json_data)



# Create your views here.
def registerPage(request):
    return render(request,"register.html")


@csrf_exempt #屏蔽装饰器器
def registerApi(request):
    if request.method == 'POST':
        req = json.loads(request.body) #取得数据
        userID = req['userID']
        pwd = req['pwd']
        print(userID,pwd)
        if len(userID) < 8 or len(userID) <= 0:
            massage = '您输入的账号小于8位，请重新输入'
            json_data = {
                'result': 200,
                'msg': massage
            }
            return JsonResponse(json_data)
        if len(pwd) <= 0:
            massage = '请您输入密码'
            json_data = {
                'result': 200,
                'msg': massage
            }
            return JsonResponse(json_data)
